package com.hen.web.henweb.model.enumeration;

import java.util.Arrays;

/**
 * @author 狠穿
 * @version 1.0.0
 * @date 2023/4/30
 * @function 状态码和响应消息枚举
 */
public enum StatusMsgEnum {

    SUCCESS(200,"成功"),
    FAIL(400,"失败"),
    ACCOUNT_NOT_EXIST(1002,"账号不存在"),
    PASSWORD_ERROR(1003,"密码错误"),
    METHODS_NOT_ALLOWED(402,"方法不允许");

    private int code;
    private String msg;

    StatusMsgEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    /**
     * 根据状态码获取对应的枚举对象
     * @param code 待转换的状态码
     * @return StatusMsgEnum
     */
    public static StatusMsgEnum parse(Integer code){
        StatusMsgEnum[] values = StatusMsgEnum.values();
        return Arrays.stream(values).filter(statusMsgEnum -> statusMsgEnum.getCode() == code).findAny().get();
    }
}
